{% extends 'base.html' %}
{% load markup %}
{% block css %}
    <link href="/site_media/bootstrap-tagsinput/bootstrap-tagsinput.css" rel="stylesheet">
    <link href="/site_media/css/pygments-css-master/emacs.css/" rel="stylesheet">
    <link href="/site_media/wmd/wmd.css/" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="row">
        <form class="form-signin2" role="form" id="themeform" action="/manage/add/" method="post">
         {% csrf_token %}
            <h2 class="form-signin-heading">发布博客</h2>
            <p><b>标题：</b></p>
            {{ form.title }}
            <p><b>类型：</b></p>
            {{ form.type }}
            <div class="btn-group" id="codes">
               {% for obj in codes %}
                <button type="button" class="btn btn-default" style="margin-right: 10px;display: block" id="c_{{ obj.id }}">{{ obj.name }}</button>
               {% endfor %}
               <input type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#addType" style="margin-right: 10px;display: block" id="adds" value="添加分类">
            </div>
            <p><b>加密：</b></p>
            {{ form.is_show }}
            <p></p>

            <div class="panel panel-default">
                  <div class="panel-heading"><b>内容：</b></div>
                  <div class="panel-body">
                    {{ form.content }}
                  </div>
            </div>
              <!--预览-->
              <div class="panel panel-default" id="prew_box">
                  <div class="panel-heading">内容即时预览</div>
                  <div class="panel-body">
                    <div id="prew_c"></div>
                  </div>
              </div>

            <p><b>添加标签：</b></p>
            <div>
                <input type="text" id="yourtags" data-role="tagsinput" placeholder="添加标签" />

            </div>
            {% if has_tags %}
                 <p id="has_tags" style="display: none">已存在的标签：{% for obj in has_tags %}<span class="label label-primary" onclick="addIt('{{ obj.tag.name }}')">{{ obj.tag.name }}</span>{% endfor %}
            {% endif %}
            {% if tags %}<p id="tags_">已存在的标签：{% for obj in tags %}<span class="label label-primary" onclick="addIt('{{ obj.name }}')">{{ obj.name }}</span>&nbsp;{% endfor %}</p>{% endif %}
            <input type="hidden" name="id_tag" value=""/>
            <input type="hidden" name="edit_or_creat" value="{{ is_edit }}" />
            <a href="javascript:;" id="submit" class="btn btn-lg btn-primary btn-block"  data-loading-text="正在加载...">发　布</a>
        </form>
  </div>
    <br/>  <br/>


<!-- Modal 添加标签 -->
<div class="modal fade" id="addType" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">添加标签:</h4>
      </div>
      <div id="s_ms_box">
      <div class="modal-body">
        <form role="form">
          <div class="form-group">
            <label for="msTitle">名称</label>
            <p class="small" style="color: #c04b4b; font-weight: bold; display: none" id="ms_title">*标题必填</p>
            <input type="type" class="form-control" id="msTitle" placeholder="名称">
          </div>

        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-info" onclick="addType()">添加</button>
      </div>
      </div>

      <div id="sendok" style="display: none">
          <div class="modal-body">
          <p id="tips">添加成功</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


{% endblock %}
{% block js %}
    <script src="/site_media/js/main.js"></script>
    <script src="/site_media/bootstrap-tagsinput/bootstrap-tagsinput.js"></script>
    <script src="/site_media/wmd/wmd.js"></script>
    <script src="/site_media/wmd/showdown.js"></script>
    <script>
    var IS_EDIT = location.href.split('=').length;
    $(function(){
        $('#prew_c').append($('.wmd-panel:last'));
        $('#id_type').hide();
        if(IS_EDIT == 2){ // 编辑状态
            var type = $('#id_type').val();
            $('#c_'+type).addClass('btn btn-success');
            $('#has_tags').children('span').each(function(){
                $(this).bind('click', addIt($(this).text()))
            })
        }
    })
    </script>
{% endblock %}
